from time import*
m1_sorted = open("m1_sorted.txt").readlines()
m2_reverse = open("m2_reverse.txt").readlines()
m3_shuffle = open("m3_shuffle.txt").readlines()
m1 = list()
m2 = list()
m3 = list()
for i in range(len(m1_sorted)):
    m1.append(int(m1_sorted[i]))

for i in range(len(m2_reverse)):
    m2.append(int(m2_reverse[i]))

for i in range(len(m3_shuffle)):
    m3.append(int(m3_shuffle[i]))
    
time_1 = time()
for i in range(len(m1)-1):
    k = 0
    for j in range(len(m1)-i-1):
        if m1[j]>m1[j+1]:
            m1[j], m1[j+1]=m1[j+1],m1[j]
            k += 1
    if k == 0:
        break
time_2 = time()
total_time1 = time_2 - time_1

time_21 = time()
for i in range(len(m2)-1):
    k=0
    for j in range(len(m2)-i-1):
        if m2[j] > m2[j+1]:
            m2[j], m2[j+1] = m2[j+1],m2[j]
            k+=1
    if k == 0:
        break
time_22 = time()
total_time2 = time_22 - time_21

time_31 = time()
for i in range(len(m3)-1):
    k=0
    for j in range(len(m3)-i-1):
        if m3[j] > m3[j+1]:
            m3[j],m3[j+1] = m3[j+1],m3[j]
            k+=1
    if k == 0:
        break
time_32 = time()
total_time3 = time_32 - time_31
total_time1 *= 1000
total_time2 *= 1000
total_time3 *= 1000
print("m1_sorted", int(total_time1), "milliseconds")
print("m2_reverse", int(total_time2), "milliseconds")
print("m3_shuffle", int(total_time3), "milliseconds")
